|
|
|
|
|
|
|
To have the control actually move somewhere, you need to add code to the DragDrop() event of the form. Because youre dragging this control over the form, you need to have the form move the control. |
|
|
|
|
| Add the DragDrop() Event 1. Double-click the form. 2. Find the DragDrop() event from the Procedures combo box. 3. Add the following code to the Form_DragDrop() event: | | Sub Form_DragDrop (Source As Control, x As Single, _
y As Single)
Source.Move x, y
End Sub |  | The DragDrop() event will receive a pointer to the control thats being moved over the form. It will also be passed in the current X and Y coordinates of the mouse on the form. By using the Move method on the control being dragged, you can move this control to the location of the mouse on the form. Once the DragDrop() event is triggered by releasing the mouse, you call the Move method on the control to place that controls Top and Left properties to where the mouse is located. Of course, if you grab the control right in the middle, it will look a little funny when you drop it because the control moves to the exact mouse locationit will look as if the control jumps around, and it wont be a smooth operation. However, about the best you can do is to center the control at the mouse location. |
|
|
| Centering the Control 1. Add the following code to center the control in the middle of the mouse location: | | Sub Form_DragDrop (Source As Control, x As Single, _
y As Single)
Source.Move (x - Source.Width / 2), _
(y - Source.Height / 2)
End Sub |
|
|
|